<?php

class Soul_Validation_Helper {

	private static $_notEmpty = NULL;
	private static $_integer = NULL;
	private static $_email = NULL;
	private static $_digit = NULL;
	private static $_numeric = NULL;
	private static $_datetime = NULL;
	private static $_maxLength = NULL;
	private static $_minLength = NULL;
	private static $_rangeLength = NULL;
	private static $_maxValue = NULL;
	private static $_minValue = NULL;
	private static $_rangeValue = NULL;
	private static $_character = NULL;
	private static $_regex = NULL;

	public static function notEmpty($value){
		if(is_null(self::$_notEmpty)){
			self::$_notEmpty = new Soul_Validation_Rule_NotEmpty();
		}
		return self::$_notEmpty->check($value);
	}

	public static function isInteger($value){
		if(is_null(self::$_integer)){
			self::$_integer = new Soul_Validation_Rule_Integer();
		}
		return self::$_integer->check($value);
	}

	public static function isDigit($value){
		if(is_null(self::$_digit)){
			self::$_digit = new Soul_Validation_Rule_Digit();
		}
		return self::$_digit->check($value);
	}

	public static function isNumeric($value){
		if(is_null(self::$_numeric)){
			self::$_numeric = new Soul_Validation_Rule_Numeric();
		}
		return self::$_numeric->check($value);
	}

	public static function isEmail($value){
		if(is_null(self::$_email)){
			self::$_email = new Soul_Validation_Rule_Email();
		}
		return self::$_email->check($value);
	}

	public static function isDateTime($value){
		if(is_null(self::$_datetime)){
			self::$_datetime = new Soul_Validation_Rule_DateTime();
		}
		return self::$_datetime->check($value);
	}
	
	public static function maxLength($value, $length){
		if(is_null(self::$_maxLength)){
			self::$_maxLength = new Soul_Validation_Rule_MaxLength();
		}
		return self::$_maxLength->setLength($length)->check($value);
	}
	
	public static function minLength($value, $length){
		if(is_null(self::$_minLength)){
			self::$_minLength = new Soul_Validation_Rule_MinLength();
		}
		return self::$_minLength->setLength($length)->check($value);
	}
	
	public static function rangeLength($value, $min, $max){
		if(is_null(self::$_rangeLength)){
			self::$_rangeLength = new Soul_Validation_Rule_RangeLength();
		}
		return self::$_rangeLength->setMin($min)->setMax($max)->check($value);		
	}
	
	public static function maxValue($value, $max){
		if(is_null(self::$_maxValue)){
			self::$_maxValue = new Soul_Validation_Rule_MaxValue();
		}
		return self::$_maxValue->setValue($length)->check($value);
	}
	
	public static function minValue($value, $length){
		if(is_null(self::$_minValue)){
			self::$_minValue = new Soul_Validation_Rule_MinValue();
		}
		return self::$_minValue->setValue($length)->check($value);
	}
	
	public static function rangeValue($value, $min, $max){
		if(is_null(self::$_rangeValue)){
			self::$_rangeValue = new Soul_Validation_Rule_RangeValue();
		}
		return self::$_rangeValue->setMin($min)->setMax($max)->check($value);		
	}	
	
	public static function isCharacter($value){
		if(is_null(self::$_character)){
			self::$_character = new Soul_Validation_Rule_Character();
		}
		return self::$_character->check($value);		
	}	
	
	public static function testRegex($value, $pattern){
		if(is_null(self::$_regex)){
			self::$_regex = new Soul_Validation_Rule_Regex();
		}
		return self::$_regex->check($value);
	}
}